import threading
import time
from typing import Callable, Any, Iterable, Mapping


def do_something1(name, delay):
    print(f'线程{name}执行任务.....')
    sum1 = 0
    for i in range(1, 10):
        sum1 += i
        print(f'线程{name} sum1 = {sum1}')
        time.sleep(delay)

    print(f'sum = {sum1} 线程{name} {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}完成任务.....')


if __name__ == '__main__':
    try:

        t1 = threading.Thread(target=do_something1, args=("thread1", 2))
        t2 = threading.Thread(target=do_something1, args=("thread2", 3))
        t1.start()
        t2.start()
        # join 堵塞主线程，让线程1和线程2执行完
        t1.join()
        t2.join()
        print("退出主线程")
    except:
        print("Error: 无法启动线程")
